var vm=new Vue({
    el:"#wrapper",
    data(){
        return {
            name:$.cookie("lastname"),
            secondlist:[],
            editlist:[]
        }
    },
    mounted:function () {
        this.alllist();
    },
    methods:{
        submitedit:function(){
            var ids=$(".idw").text();
            var time=$(".time").val();
            var broker=$(".broker").val();
            var type=$(".type").val();
            var hourseid=$(".hourseid").val();

            var params1 = new URLSearchParams();
            params1.append("id",ids);
            params1.append("time",time);
            params1.append("broker",broker);
            params1.append("type",type);
            params1.append("hourseid",hourseid);

            axios.post('http://localhost:8080/last/recordedit',params1).then(res=>res.data).then(data=>{
                this.secondlist=data;
                var lenth=this.secondlist.length;
                for(var i=0;i<lenth;i++){
                    Vue.set(vm.secondlist, i, data[i]);
                }
            })
        },

        edit:function(index){
            var params1 = new URLSearchParams();
            params1.append("id",index);
            axios.post('http://localhost:8080/last/recordedit1',params1).then(res=>res.data).then(data=>{
                this.editlist=data;
            })
        },
        alllist:function () {
            axios.post('http://localhost:8080/last/recordlist').then(res=>res.data).then(data=>{
                this.secondlist=data;
                var pageCount=data.length;
                var options = {
                    currentPage: 1,
                    totalPages: 4,
                    numberOfPages:10,
                    bootstrapMajorVersion:3,
                    onPageClicked:function clickpage(event, originalEvent, type, page){
                        var params1 = new URLSearchParams();
                        params1.append("page",page);
                        axios.post('http://localhost:8080/last/recordlist',params1).then(res=>res.data).then(data=>{
                            this.secondlist=data;
                            var lenth=this.secondlist.length;
                            for(var i=0;i<lenth;i++){
                                if(data[i]!=null) {
                                    Vue.set(vm.secondlist, i, data[i]);
                                }else{
                                    Vue.set(vm.secondlist,i,null)
                                }
                            }
                            console.log(data)
                        })
                    }
                }
                $('#pageLimit').bootstrapPaginator(options);
            })
        },
        add:function () {
            var time=$("#time").val();
            var broker=$("#broker").val();
            var type=$("#type").val();
            var hourseid=$("#hourseid").val();
            var params1 = new URLSearchParams();
            params1.append("time",time);
            params1.append("broker",broker);
            params1.append("type",type);
            params1.append("hourseid",hourseid);
            axios.post('http://localhost:8080/last/recordadd',params1).then(res=>res.data).then(data=>{
                this.secondlist=data;
                var lenth=this.secondlist.length;
                for(var i=0;i<lenth;i++){
                    Vue.set(vm.secondlist, i, data[i]);
                }
                alert("添加成功")
            })
        },
        del:function (index) {
            var params = new URLSearchParams();
            params.append("id",index);
            axios.post('http://localhost:8080/last/recorddel',params).then(res=>res.data).then(data=>{
                this.secondlist=data;
                var lenth=this.secondlist.length;
                for(var i=0;i<lenth;i++){
                    Vue.set(vm.secondlist, i, data[i]);
                }
                alert("删除成功！")
            })
        }
    }
});




$("#add1").click(function () {
    $("#modal-2").addClass("md-show");
})
$(".close1").click(function () {
    $("#modal-2").removeClass("md-show");
})
$("#closes").click(function () {
    $("#modal-3").removeClass("md-show");
})
$(".table-hover").delegate(".btn-primary","click",function () {
    $("#modal-3").addClass("md-show");
})
$("#add").click(function () {
    $("#modal-2").removeClass("md-show");
})
$("#submits").click(function () {
    $("#modal-3").removeClass("md-show");
})